package com.bruan.d2_io;

import com.bruan.d1_io.MyConnection;

import java.io.*;

public class BufferedInputStreamTest1 {
    public static void main(String[] args) {
        copyFile("D:\\Desktop\\hhh.jpg","D:\\Desktop\\new_dir_test_idea\\hhh.jpg");
    }
    public static void copyFile(String file1,String file2){
        //jdk7新加入的释放资源方法
        try(
                InputStream inputStream = new FileInputStream(file1);
                OutputStream outputStream = new FileOutputStream(file2);
                InputStream bis =  new BufferedInputStream(inputStream);
                OutputStream bos = new BufferedOutputStream(outputStream);
        ){
            byte[] buffer = new byte[1024];
            //从字节输入流写出到字节输出流
            int len;
            while ((len=bis.read(buffer))!=-1){
                bos.write(buffer,0,len);
            }
            System.out.println("复制成功");
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
